# -*- coding:utf-8 -*-
"""
Created on 2016年2月15日
@author: yytan 77890
"""
from pyse.mail import config_mail
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart


class SendMail(object):
    def send_mail(self, new_report):
        # 发送的附件
        sendfile = open(new_report, 'rb').read()
        # 编写正文
        msgRoot = MIMEMultipart('related')
        msgRoot['Subject'] = config_mail.subject
        msg = MIMEText(sendfile, 'html', 'utf-8')
        msgRoot.attach(msg)
        # 附件部分
        att = MIMEText(sendfile, 'base64', 'utf-8')
        att["Content-Type"] = 'application/octet-stream'
        att["Content-Disposition"] = 'attachment; filename="TestReport.html"'
        msgRoot.attach(att)
        # 连接发送邮件
        smtp = smtplib.SMTP()
        smtp.connect(config_mail.smtpserver)
        smtp.login(config_mail.user, config_mail.password)
        smtp.sendmail(config_mail.sender, config_mail.receiver, msgRoot.as_string())
        smtp.quit()
        print('=> 邮件发送成功')

if __name__ == '__main__':
    SendMail().send_mail('C:/Python/Python35/Lib/site-packages/pyse/demo/report/2017-09-18_16_40_25result.html')
